package bloodfang.client;

import java.io.*;
import java.net.*;

import org.json.JSONException;
import org.json.JSONObject;

import bloodfang.Stat;

public class Client {
    public static void main(String[] args) throws IOException, JSONException {

        Socket echoSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;

        try {
            echoSocket = new Socket("localhost", 4444);
            out = new PrintWriter(echoSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader(
                                        echoSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Don't know about host");
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't get I/O for the connection");
            System.exit(1);
        }
				
		// build json string object
		JSONObject json = new JSONObject();
		
		json.put("race", "dwarf");
		
		JSONObject stats = new JSONObject();
		stats.put(Stat.str.name(), 80);
		stats.put(Stat.agi.name(), 18078);
		stats.put(Stat.cri.name(), 4170);
		stats.put(Stat.hst.name(), 9086);
		stats.put(Stat.mst.name(), 5576);
		stats.put(Stat.mul.name(), 2251);
		json.put("stats", stats);
		
		JSONObject mh = new JSONObject();
		mh.put("dps", 4301.7);
		mh.put("speed", 2.6);
		mh.put("type", "mace");
		json.put("mh", mh);
		
		JSONObject oh = new JSONObject();
		oh.put("dps", 3570.4);
		oh.put("speed", 1.8);
		oh.put("type", "dagger");
		json.put("oh", oh);
		
		json.put("tal", "221102");
		
		json.append("set", "T15_2PC");
		json.append("set", "T15_4PC");
		
		json.append("procs", new JSONObject().put("proc", "shado_pan_assault").put("lvl", 2));
		json.append("procs", new JSONObject().put("proc", "lfr_renatakis_soul_charm").put("lvl", 0));
		json.append("procs", new JSONObject().put("proc", "capacitive_primal_diamond").put("lvl", 0));
		json.append("procs", new JSONObject().put("proc", "mh_dancing_steel").put("lvl", 0));
		json.append("procs", new JSONObject().put("proc", "oh_dancing_steel").put("lvl", 0));
		
		
		out.println(json.toString());
		System.out.println("echo: " + in.readLine());
	
		out.close();
		in.close();
		echoSocket.close();
    }
}
